{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId = \"emy_test\" #学生填写\n",
    "create_facelists_url = \"https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}\" #学生填写\n",
    "subscription_key = \"4f253843772f42e89e959977f6149561\" #学生填写\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "    \"name\": \"相册集01\",\n",
    "    \"userData\": \"各种相片\",\n",
    "    \"recognitionModel\": \"recognition_03\", # 学生填写\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) #学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"error\":{\"code\":\"FaceListExists\",\"message\":\"Face list \\'emy_test\\' already exists.\"}}'"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url =\"https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces\"\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://huangjieqi.gitee.io/picture_storage/hjq.jpg\"#学生填写\n",
    "\n",
    "params_add_face={\n",
    "     \"userData\":\"hjq\"\n",
    "#学生填写\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaceId': '417e2b66-5133-48ba-8502-7c2c94b3138c'}"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.json()#返回persistedFaceId"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-hjq.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "429"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/ltco.jpg\",\"李婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg\",\"黄智毅\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg\",\"黄慧文\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg\",\"张铭睿\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/yichenting.jpg\",\"陈婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/coco022.jpg\",\"洪可凡\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lujizhi.png\",\"卢继志\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg\",\"张梓乐\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '7b8eb914-519b-4bcd-809c-ae981d1f1d32',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '543d3fe2-0921-4df2-b006-52e41ba7a4ed',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '0d41e6a2-0a20-4958-9fe6-51fa9f6f92cd',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '266da870-65bb-4766-906f-e54a933c6530',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'b1d900ed-4c13-42bd-85d3-2c20ed25c49e',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '0d9828ae-3b17-42fd-a593-858c8c75cb23',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '753e0917-6109-447e-a382-2b1e6ebe24e4',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '57df4834-be27-4165-9638-eac39d9a70e0',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '6772dde9-3953-4e3f-b601-c66b1f7ffcd0',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '03e79ea9-442f-47c7-83b2-32bc46d8eeab',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '79a5f04d-70c5-41fc-b8e8-61b5484ae1be',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '2e8055db-8c7b-4557-b3dc-abc1c123005e',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '56cae861-f30b-4c1a-95da-228d7731e406',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'da6ce1ec-de88-4e4b-bc87-b57ca38931ab',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '746f9da8-f14e-4c22-975a-d13d15aba4ed',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': 'fddaf981-090c-4294-aa96-7aa06a560aa3',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'b6be6099-86d1-4016-a5f1-8b35585244c8',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': 'c2660c80-2ead-4909-97f8-93f7bc3cb451',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': '61f51297-29a3-4547-8eb5-dceaf1c6d7f0',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': '1fdf47e1-d5ad-457c-8dbd-1aa9a6dd2ff2',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '55d10812-93ad-487c-9b61-b64e33117671',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '0c522bd4-8c40-46b2-b4a7-acd92cfb6c68',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '70b63980-8d35-426e-a30b-df2fac9a614c',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'd625dadc-c872-439a-9783-9629cfcb0065',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '4cc60c3e-75ee-465e-8c77-1febb2f63596',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '75e08329-bd2a-406e-81c7-9673fe5c8484',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '1f274f09-b52c-4100-a662-14a5a8458ec0',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '48f901f6-4efe-49cc-84ae-0c966cb114d1',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': 'cfb321f9-2cbc-472c-93ca-cdc3c44f2cdf',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '27949e7c-d792-4b01-a237-9f9223d1fbbc',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '0c3308e9-d57e-4d0d-abc4-b7de493d0a71',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': 'c5a636a2-addc-494d-a095-0a1cca3c126a',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'b5993135-ffc0-4572-ae43-6d05a25b90c1',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '9a4bcda8-7063-4787-a7ec-9869722370f3',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '342aa231-b140-4a63-9f29-49d7424fdbbd',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'c7ac8856-8174-49f5-98c2-37f47045687f',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '2ea1c809-d601-4012-bd3a-03494277db5e',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'a374ff3c-4506-4a64-b141-aaac3974dedd',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': 'dab92670-2c13-4b29-af33-0696c2dc58ea',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '86f5b2ad-1682-48a5-9961-da0eca45e7c1',\n",
       "   'userData': '张梓乐'},\n",
       "  {'persistedFaceId': '1a28e432-d408-499a-a518-30779e500ef1',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '31026fa5-c4af-40e2-9cc0-6cdaeb2aafef',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '1ca86b0d-79ba-461a-8c3e-170adf85609f',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '361f27da-9131-4632-b296-9da91134b491',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '5de0f0b5-65f9-413e-a2a7-75f9991c1c89',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': 'b87a8012-5605-43b9-bd71-c41ac060a77d',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '5318f9e2-ea7b-4af6-a60c-fb8798bce74a',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': 'c80f9c33-8359-4d38-b82b-4fabd4e7fc74',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '01342233-ae68-4190-b102-defc9cc404af',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': 'd82308e4-3448-41d7-9dcd-fa3a05716a12',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '509636e3-9e3e-41dc-ab6a-2487fe7ea69b',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'd56937e0-1af8-46c6-aea0-39cec58da718',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': 'bf17d59e-d6d8-46f6-823b-61b502d3316c',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '5543ee51-207c-4cec-936a-2ec2124a78b4',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': 'd2ddfde7-55f3-400b-8952-76a3c6f0bd2a',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '56d8519b-dcf9-4a18-b953-3b63c65bbe0b',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '412aa172-78fe-49ba-a722-fed797a90fb3',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '9514c4fd-d13a-4cd5-8fe4-eeb6c7ffcbc9',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'ca0e8bc1-50be-4ca0-b74c-f336096c06b6',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': 'db4bc356-b4cd-4758-b360-071b2d508082',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '4103de15-7558-46ae-9a68-c1f92ddbda3b',\n",
       "   'userData': '张梓乐'},\n",
       "  {'persistedFaceId': '3727eea8-8849-457d-9fcc-d87cb15ef5bd',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '3a1b42ed-a21e-44a0-99d2-bd3bfe362330',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '69593b26-75f0-4cc6-a230-07241bddbece',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'dda620d3-0738-406a-a5af-fe38d300aedf',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': 'ea36159d-33a2-4973-955d-702551cceea7',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '07d6ac02-0459-4261-ab8c-718cebfc98fa',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '668579d6-b8d3-4544-9187-8f7610037a5f',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '1ed24954-9d03-47a7-820c-50d1377fe9d4',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '4bb85532-fae0-4c64-9600-110c14e3c4d5',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': 'ee8a36f8-0e42-4059-ba6c-c9e0766b2dbb',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'ce13325e-fdc7-4616-8446-98e0701077ec',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '94a46cf5-7d2d-47c6-ac30-86647579534f',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '27438f94-0c65-4bf6-87c2-d552dc81f726',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '3213ef05-fa38-4125-a738-36e23c6e6ef9',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '6b6e984c-2f92-4ec0-be86-1c940d348dda',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '8d3e8643-5f92-487d-bc6c-4c38e566dd17',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '62d3826b-9725-46f3-8f15-3312ad1571d5',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': 'f5697f19-01a2-492e-8e13-d976eddf4725',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '5d5837ae-6749-4d8c-9830-e07d723485ce',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '619d7a41-20f2-4f2d-a5ab-689d5bcbbc74',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '203be7b7-e221-4c1f-8687-3298223cb170',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '12672b18-ea14-445b-9354-0612d05268bb',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': 'cc68305e-6e6b-4ad7-a64a-cc2a9e10181a',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '2906ebbc-5ace-493b-99bd-46ce15a633ed',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '7e77673b-4899-4430-8cf8-317a3986f294',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '020a399f-c1fa-4899-a8ae-f18e333138a4',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': '0c0260d1-0ff9-4f6e-8011-fb3f94d9a142',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': '417e2b66-5133-48ba-8502-7c2c94b3138c',\n",
       "   'userData': 'hjq'},\n",
       "  {'persistedFaceId': '02b64f9e-6b84-48ab-b14d-f3fb42e45db2',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'fb6073f3-d8f8-437e-94a3-07ea6dae0d5a',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '81cd79bb-cc88-4d7b-95be-159e433b8bb3',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '4a9bd872-352b-412e-b6a6-8e6263b94bd6',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '5188075a-339e-4968-93cd-7c1d6025f781',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': 'f6499deb-df9a-495c-a938-6c3130adabc2',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': 'f09ed581-710a-48a0-8dd4-84053c32f3e2',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': 'b4878964-43bc-46b1-8fab-a3d5471ce2fb',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '95234862-e0df-4e25-a718-60da3ee3e779',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': '8cc74d43-4fc7-496f-94d9-8660bf90b946',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'b5f4ccf3-3385-4f10-b6b3-5950135dbe35',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': 'e88f89c2-9d63-4b69-a36e-28cc2fa826d0',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'd138ea30-763f-4fc5-93b3-4d8322240600',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': 'c631d328-c3eb-49bd-867e-454fa0f7d53f',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': 'e8363bf7-d09a-40f9-a903-82f7ec6a7d10',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'cb83a8fb-7fea-4545-b697-f058708010fa',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': 'f34c237c-9f84-4268-8e94-8c63fa1401e1',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'cbe99085-26de-4f3a-92ce-70c20ec16243',\n",
       "   'userData': '洪可凡'}],\n",
       " 'faceListId': 'emy_test',\n",
       " 'name': '相册集01',\n",
       " 'userData': '各种相片'}"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = \"https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}\"# 学生填写\n",
    "r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "faceListId = \"emy_test\" #删除人脸列表 # 学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Delete face 删除列表内人脸id\n",
    "delete_face_url = \"https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces/{}\"\n",
    "\n",
    "assert subscription_key\n",
    "persistedFaceId = r_add_face.json()[\"persistedFaceId\"]\n",
    "# 直接取上面获得的ID{'persistedFaceId': 'f18450d3-60d2-45f3-a69e-783574dc3ce8'} \n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# 注意requests请求为delete\n",
    "r_delete_face = requests.delete(delete_face_url.format(faceListId,persistedFaceId),headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '149f3858-1984-4d16-b6cf-846e49727857',\n",
       "  'faceRectangle': {'top': 264, 'left': 207, 'width': 277, 'height': 277},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 1.7, 'roll': -19.8, 'yaw': -13.9},\n",
       "   'gender': 'male',\n",
       "   'age': 21.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.002,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.969,\n",
       "    'sadness': 0.029,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.44},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.68},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.39},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.18,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.97},\n",
       "     {'color': 'black', 'confidence': 0.9},\n",
       "     {'color': 'red', 'confidence': 0.38},\n",
       "     {'color': 'other', 'confidence': 0.23},\n",
       "     {'color': 'blond', 'confidence': 0.15},\n",
       "     {'color': 'gray', 'confidence': 0.09},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://face-ozl.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'http://huangjieqi.gitee.io/picture_storage/hjq.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://face-ozl.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"149f3858-1984-4d16-b6cf-846e49727857\",#取上方的faceID\n",
    "    \"faceListId\": \"emy_test\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '7b8eb914-519b-4bcd-809c-ae981d1f1d32',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '1fdf47e1-d5ad-457c-8dbd-1aa9a6dd2ff2',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '1a28e432-d408-499a-a518-30779e500ef1',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '3727eea8-8849-457d-9fcc-d87cb15ef5bd',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '3a1b42ed-a21e-44a0-99d2-bd3bfe362330',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '4bb85532-fae0-4c64-9600-110c14e3c4d5',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '417e2b66-5133-48ba-8502-7c2c94b3138c',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '79a5f04d-70c5-41fc-b8e8-61b5484ae1be',\n",
       "  'confidence': 0.29269},\n",
       " {'persistedFaceId': '27949e7c-d792-4b01-a237-9f9223d1fbbc',\n",
       "  'confidence': 0.29269},\n",
       " {'persistedFaceId': '509636e3-9e3e-41dc-ab6a-2487fe7ea69b',\n",
       "  'confidence': 0.29269}]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
